package temp.lho.lws.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import temp.lho.lws.emum.MsgStatusEmum;
import temp.lho.lws.pojo.ObjectDamageInfo;
import temp.lho.lws.result.ResultBody;
import temp.lho.lws.service.IObjectDamageInfoService;
import temp.lho.lws.vo.LayuiResult;

import java.util.List;

/**
 * (ObjectDamageInfo)表控制层
 *
 * @author makejava
 * @since 2020-07-06 23:08:54
 */
@RestController
@RequestMapping("/objectDamageInfo")
public class ObjectDamageInfoController {
    /**
     * 服务对象
     */
    @Autowired
    private IObjectDamageInfoService objectDamageInfoService;

    @PostMapping("/addObject")
    public ResultBody addObject(@RequestBody ObjectDamageInfo objectDamageInfo) {
        int add = objectDamageInfoService.add(objectDamageInfo);
        return add > 0 ?
                ResultBody.toResultBody(MsgStatusEmum.ADD_SUCCESS.getCode(),
                        MsgStatusEmum.ADD_SUCCESS.getMsg()):
                ResultBody.toResultBody(MsgStatusEmum.ADD_ERROR.getCode(),
                        MsgStatusEmum.ADD_ERROR.getMsg());
    }

    @GetMapping("/findByClaimmainid/{claimmainid}")
    public LayuiResult findByClaimmainid(@PathVariable Integer claimmainid) {
        List<ObjectDamageInfo> byClaimmainid = objectDamageInfoService.findByClaimmainid(claimmainid);
        if (byClaimmainid != null && byClaimmainid.size() != 0) {
            return new LayuiResult(0,"",byClaimmainid.size(),byClaimmainid);
        } else {
            return new LayuiResult(0,"",0,null);
        }
    }

    @GetMapping("/deleteObject")
    public ResultBody deleteObject(Integer objectdamage) {
        int delete = objectDamageInfoService.delete(objectdamage);
        return delete > 0 ?
                ResultBody.toResultBody(MsgStatusEmum.DELETE_SUCCESS.getCode(),
                        MsgStatusEmum.DELETE_SUCCESS.getMsg())
                :ResultBody.toResultBody(MsgStatusEmum.DELETE_ERROR.getCode(),
                MsgStatusEmum.DELETE_ERROR.getMsg());
    }

}